//
//  CommentTableViewCell.m
//  110
//
//  Created by 沈鑫 on 16/4/11.
//  Copyright © 2016年 乔砥. All rights reserved.
//

#import "CommentTableViewCell.h"

@implementation CommentTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self == [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        _titleLabel = [[UILabel alloc]initWithFrame:CGRectMake(5, 5, 150, 20)];
        _titleLabel.textColor = [UIColor blueColor];
        [self.contentView addSubview:_titleLabel];
        
        _deliteLabel = [[UILabel alloc]initWithFrame:CGRectMake(5, 30, KWIDTH - 65, 20)];
        _deliteLabel.numberOfLines = 0;
        _deliteLabel.textColor = [UIColor grayColor];
        [self.contentView addSubview:_deliteLabel];
        
        _button = [UIButton buttonWithType:UIButtonTypeCustom];
        _button.frame = CGRectMake(KWIDTH - 55, 5, 30, 30);
        [_button setImage:[UIImage imageNamed:@"zan"] forState:UIControlStateNormal];
        [self.contentView addSubview:_button];
        
        _buttonLabel = [[UILabel alloc]initWithFrame:CGRectMake(KWIDTH - 90, 5, 30, 30)];
        _buttonLabel.textColor = [UIColor blueColor];
        [self.contentView addSubview:_buttonLabel];
    }
    return self;
}

- (void)cellConfigurenodel:(CommentModel *)model
{
    _titleLabel.text = model.username;
    if (_titleLabel.text.length == 0)
    {
        _titleLabel.text = @"匿名";
    }
    _buttonLabel.text = [NSString stringWithFormat:@"%ld",model.useful];
    _deliteLabel.text = model.content;
    CGRect bounds = [model.content boundingRectWithSize:CGSizeMake(150, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:15] forKey:NSFontAttributeName] context:nil];
    self.deliteLabel.frame = CGRectMake(5, 40, KWIDTH - 65, bounds.size.height);
}

+ (CGFloat)cellHeghtForRow:(CommentModel *)model
{
    CGRect bounds = [model.content boundingRectWithSize:CGSizeMake(150, 1000) options:NSStringDrawingUsesLineFragmentOrigin attributes:[NSDictionary dictionaryWithObject:[UIFont systemFontOfSize:15] forKey:NSFontAttributeName] context:nil];
    return 30 + bounds.size.height + 10;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
